<?php
/**
 * The Template for displaying all single posts.
 *
 * @package WordPress
 * @subpackage Twenty_Eleven
 * @since Twenty Eleven 1.0
 */

get_header(); ?>

		<div id="primary" class="pagedefault">
			<div id="content" role="main" class="clearfix">
    			<div class="leftpage aleft">
                    <img src="/wp-content/uploads/2012/12/attendees-214x112.png"/>    
                    <div id="search_description" class="search_description">                  
                        <div id="search">
                            <div class="content-search">
                                <div class="body">
                                   <strong>Search by:</strong> 
                                   <form action="" method="get" id="frmSearch" name="frmSearch">
                                    <?php                                        
                                        update_post_meta($post->ID, 'detail_count',  get_post_meta($post->ID, 'detail_count', TRUE) + 1);    
            
                                        $terms = wp_get_post_terms( $post->ID, 'bs_category');
                                        $cat_id = $terms[0]->term_id;
                                        $sql = "select category_id, field_key, field_label, field_type from wp_category_fields a
                                                inner join wp_content_fields b on b.id = a.field_id
                                                where search = 1 and category_id=".$cat_id." order by b.weight desc";
                                                
                                        $db = $wpdb->get_results($sql);
                                        
                                        foreach($db as $field ) {
                                            if($field->field_type=='textfield') {
                                                print '<input rel="'.$field->field_label.'" size="15" type="text" value="'.$field->field_label.' & Keyword" id="'.$field->field_key.'" id="'.$field->field_key.'">
                                                        <input type="image" src="'.get_template_directory_uri().'/images/searchBtn.jpg" class="img-button">';
                                            } else {
                                                print '<div class="select"><div id="text_'.$field->field_key.'" class="text">--'.$field->field_label.'--</div>';
                                                print select_control($field->field_key,$field->field_type,$_GET['catid'], $val, false, 'styled', $field->field_label);
                                                print '</div>';
                                            }
                                        }
                                    ?>
                                   </form> 
                                </div>
                            </div>
                        </div>
                    </div>
                    <ul class="pagemenu business-detail" id="menu-attendees">
                        <li>
                            < <a href="javascript: history.go(-1);"><strong>Back to Hotels</strong></a>
                        </li>
                    </ul>
                    
                </div><!--/.leftpage-->
                <div class="mainpage aleft" id="business-detail">
                    <img border="0" title="Business Detail" alt="Business Detail" src="<?php echo get_template_directory_uri(); ?>/images/h_business_detail.jpg">
                	<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                        <!-- AddThis Button BEGIN -->
            			<script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script>
            			<div style="float:right"  class="addthis_toolbox addthis_default_style">
            			<a href="http://www.addthis.com/bookmark.php?v=250&amp;username=sdccc" class="addthis_button_compact">Share</a>
            			<span class="addthis_separator">|</span>
            			<a class="addthis_button_facebook"></a>
            			<a class="addthis_button_email"></a>
            			<a class="addthis_button_favorites"></a>
            			<a class="addthis_button_print"></a>
            			</div>
            			<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=sdccc"></script>
            			<script type="text/javascript">
            			$(document).ready(function(){
            				$('.addthis_button_facebook').click(function(){
            					var fb_url = 'http:' + $(this).attr('href');
            					window.open(fb_url, "Facebook", "height=327, width=680");
            					return false;
            				});
            			});
            			</script>
                        <!-- end -->
                        <?php
                            $website = strtolower(get_post_meta($post->ID, 'field_website', TRUE));
                            if(substr($website,0,7)!='http://') $website = 'http://'.$website;
                            
                            $arr_not_show = array('field_phone','field_neighborhood','field_proximitytoSDCC','field_numofrooms','field_mumomeetingrooms',
                                                    'field_hotelregion','field_cuisine','field_pricerange','field_onlinereservationlink',
                                                    'field_buytickets','nightlife_scene','field_max_reception','field_max_banquet',
                                                    'field_max_theater');
                        
                            
                            
                            
                        ?>
                    		<div class="entry-header-title">                                
                                <?php if(get_post_meta($post->ID, 'field_photo', TRUE)) { ?>
                                <div class="photo">
                                    <img height="200" width="200" alt="<?php print $post->post_title; ?>" src="/<?php print get_post_meta($post->ID, 'field_photo', TRUE);?>">
                                </div>
                                <?php } ?>  
                                <div class="content-right">                              
                        			<h3><?php the_title(); ?></h3>                	
                        			<div class="address">
                                        <strong>Address:</strong><br />
                                        <?php print get_post_meta($post->ID, 'field_address', TRUE).
                                                '<br />'.get_post_meta($post->ID, 'field_city', TRUE).
                                                ', '.get_post_meta($post->ID, 'field_zip', TRUE);
                                             $add_map_location =  get_post_meta($post->ID, 'field_address', TRUE).
                                                                ', '.get_post_meta($post->ID, 'field_city', TRUE).
                                                                ', '.get_post_meta($post->ID, 'field_zip', TRUE);
                                              $add_map_location = str_replace(' ','+',$add_map_location); 
                                        ?>
                                    </div>
                                    <div class="map_website">
                                        <a href="#viewmap">View map</a><br />
                                        <a target="_blank" href="<?php print $website;?>">Visit Website</a>
                                    </div>
                                    <br clear="all">
                                    <p>
                                    <?php
                                        $arr_select = array('cuisine','hotelregion','neighborhood','pricerange');
                                        $sql = "SELECT * FROM ".$wpdb->prefix."category_fields wpcf 
                                                INNER JOIN ".$wpdb->prefix."content_fields wpcf1 ON wpcf.field_id=wpcf1.id
                                                WHERE wpcf.category_id=$cat_id ORDER BY wpcf1.weight";
                                        $db = $wpdb->get_results($sql);
                                        foreach($db as $data) {                                           
                                            if(in_array($data->field_key,$arr_not_show)){
                                                $text_value = get_post_meta($post->ID,$data->field_key, TRUE);
                                                if(!empty($text_value)){
                                                    if(in_array($data->field_type, $arr_select)) {                                                       
                                                        $term = get_term( get_post_meta($post->ID, $data->field_key, TRUE),$data->field_type);
                                                        $text_value = $term->name;
                                                    }
                                    ?>
                                        <strong><?php print $data->field_label;?>:</strong> <?php print $text_value; ?><br />
                                    <?php       } 
                                            }
                                        } //for ?>
                                    </p>
                                </div>
                                    <p><?php print $post->post_content; ?></p>
                                    <p><strong>Map Location</strong><a name="viewmap"></a><br />
                                    <iframe width="620" scrolling="no" height="400" frameborder="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=<?php print $add_map_location;?>&amp;output=embed" marginwidth="0" marginheight="0"></iframe>                                    
                                    </p>                              
                    		</div><!-- .entry-header -->
                		</div><!-- .entry-content --> 
                	</article>
                </div>
			</div><!-- #content -->
		</div><!-- #primary -->

<?php get_footer(); ?>